package cn.lingyangwl.agile.model.enums;

import cn.lingyangwl.framework.tool.core.exception.BaseError;
import org.springframework.http.HttpStatus;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * @author shenguangyang
 */
@Getter
@AllArgsConstructor
public enum AuthErrorEnum implements BaseError {
    FAIL(HttpStatus.BAD_REQUEST,  400,"授权失败, 请联系管理员"),

    /**
     * 用户相关错误
     */
    // arg1: 时间, eg: 1分25秒
    LOGIN_LOCKED(HttpStatus.BAD_REQUEST,  400,"您的账号由于连续登录失败, 已被锁定, 还剩 {}"),
    WILL_LOCKED(HttpStatus.BAD_REQUEST,400, "还剩 %s 次将被锁定"),
    USER_REGISTER_FAIL(HttpStatus.BAD_REQUEST, 1202, "注册失败!"),
    USER_PASSWORD_EMPTY(HttpStatus.BAD_REQUEST, 1203, "登录密码不能为空!"),
    USER_MOBILE_EMPTY(HttpStatus.BAD_REQUEST, 1204, "手机号不能为空!"),
    USER_MOBILE_ERROR(HttpStatus.BAD_REQUEST, 1205, "手机号格式错误!"),
    USER_MOBILE_NOT_EXIST(HttpStatus.BAD_REQUEST,1206, "手机号不存在!"),
    USER_PASSWORD_ERROR(HttpStatus.BAD_REQUEST, 1207, "密码错误!"),
    USER_ACCOUNT_NOT_EXIST(HttpStatus.BAD_REQUEST, 1208, "账号不存在！"),
    USER_LOGIN_USERNAME_OR_PASSWORD_MISSING(HttpStatus.BAD_REQUEST, 1209, "用户/密码必须填写"),
    USER_LOGIN_PASSWORD_OUT_OF_RANGE(HttpStatus.BAD_REQUEST, 1210, "用户密码不在指定范围"),
    USER_LOGIN_USERNAME_OUT_OF_RANGE(HttpStatus.BAD_REQUEST, 1211, "用户名不在指定范围"),
    USER_USERNAME_OR_PASSWORD_ERROR(HttpStatus.BAD_REQUEST, 1212, "用户名或者密码错误"),
    USER_DISABLE(HttpStatus.FORBIDDEN, 1213, "您的账号已停用"),
    USERNAME_NOT_FOUND(HttpStatus.NOT_FOUND,1214, "账号 %s 不存在"),
    USER_NO_ASSIGN_ANY_ORG(HttpStatus.UNAUTHORIZED,401, "当前用户尚未归属于任何组织, 请联系管理员"),

    /**
     * 微信授权相关
     */
    WX_USER_NOT_EXIST(HttpStatus.NOT_FOUND, 2001, "微信用户不存在"),
    WX_DATA_PARSE_FAIL(HttpStatus.BAD_REQUEST, 2002, "解析微信响应数据失败"),

    CREDENTIALS_EXPIRED(HttpStatus.UNAUTHORIZED,401, "用户凭证已过期"),
    GRANT_TYPE_NO_MATCH(HttpStatus.UNAUTHORIZED,401, "当前 grant_type 不匹配, 请到控制台添加 grant_type 类型, 字典 = authorized_grant_types"),

    /**
     * 令牌为空或者登录过期
     */
    TOKEN_CHECK_FAIL( HttpStatus.UNAUTHORIZED, 3000, "令牌校验失败"),
    TOKEN_BLANK(HttpStatus.UNAUTHORIZED, 3001, "令牌为空"),
    TOKEN_EXPIRED(HttpStatus.UNAUTHORIZED,3002, "登录超时, 请重新登录"),

    CAPTCHA_ERROR(HttpStatus.BAD_REQUEST,3003, "验证码错误或者已过期"),
    CAPTCHA_IS_EMPTY(HttpStatus.BAD_REQUEST,3004, "验证码不能为空"),
    MISS_AUTH_HEADER(HttpStatus.BAD_REQUEST, 3005, "请求头中缺失Authorization"),
    MISS_BASIC_FORMAT(HttpStatus.BAD_REQUEST, 3006, "非法 Authorization 值格式"),

    CLIENT_NOT_EXIST(HttpStatus.BAD_REQUEST, 3007, "客户端不存在, 请联系管理员"),

    SCOPE_IS_EMPTY(HttpStatus.BAD_REQUEST, 3008, "scope不能为空"),
    OAUTH2_CLIENT_CLIENT_SECRET_ERROR(HttpStatus.BAD_REQUEST, 3009, "无效 client_secret"),
    OAUTH2_GRANT_TYPE_NOT_EXISTS(HttpStatus.BAD_REQUEST, 3010, "不支持的授权类型【{}】"),
    OAUTH2_CLIENT_SCOPE_OVER(HttpStatus.BAD_REQUEST, 3011, "授权范围过大"),
    OAUTH2_UNAUTHORIZED_CLIENT(HttpStatus.BAD_REQUEST, 3012, "未被授权的客户端"),

    /**
     * 临时授权token
     */
    OAUTH2_TMP_AUTH_TOKEN_INVALID(HttpStatus.BAD_REQUEST, 3013, "临时凭证已失效, 请重新授权登录"),
    NO_IMPL_GRANT_TYPE(HttpStatus.OK, 3014, "尚未实现 {} 登录类型"),

    QR_CODE_EXPIRED(HttpStatus.OK, 3015, "二维码已过期, 请重新生成");

    private final HttpStatus status;
    private final Integer code;
    private final String message;

}
